#include "pe12-2a.h"

#include <stdio.h>

// default mode is metric mode
static int m = 0;
static float distance = 0.0f;
static float fuel = 0.0f;

void set_mode(int mode) {
  if (0 == mode || 1 == mode) {
    m = mode;
  } else {
    printf("Invalid mode specified. Mode %d(%s) used.\n", m, get_mode(m));
  }
}

void get_info() {
  printf("Enter distance traveled in %s: ", 1 == m ? "miles" : "kilometers");
  scanf("%f", &distance);
  printf("Enter fuel consumed in %s: ", 1 == m ? "gallons" : "liters");
  scanf("%f", &fuel);
}

void show_info() {
  printf("Fuel consumption is %.*f %s per %s\n", 1 == m ? 1 : 2,
         1 == m ? distance / fuel : fuel * 100 / distance,
         1 == m ? "miles" : "liters", 1 == m ? "gallons" : "100 km");
}
